
package Managers;

import java.util.Hashtable;
import MapItens.Item;
import MapItens.ItemFactory;
import java.io.IOException;
import java.util.Enumeration;

public class ItemManager {
    
    //The itens table
    private Hashtable item_table;
    
    //The Items factory
    private ItemFactory item_factory;
    
    //The Boss
    //private FlunkerManager flunker_manager;
    
    public ItemManager(FlunkerManager manager){
        item_table = new Hashtable();
        item_factory = new ItemFactory(this, manager.getWorld());
        //flunker_manager = manager;
    }
    
    /**
     * This method allows for new items to be had to the item array
     * @params itemId its the identification number of the item
     * @params itemType its the type of the item
     */
    public void addItem(int itemId, char itemType) throws IOException{
        
        Item item = item_factory.getItem(itemType);
        if(item != null){
            item_table.put(new Integer(itemId), item);
        }
    }
    
    
    public void setAction(int itemId, int actionCode){
        
        Item item = getItem(itemId);
        item.setAction(actionCode);
    }
    
    public Item getItem(int itemId){
        return (Item) item_table.get(new Integer(itemId));
    }
    
    public void updateItens(int worldTime){
        //Go through all the itens and execute the update function of each
        Enumeration e = item_table.elements();
        while(e.hasMoreElements()){
            ((Item)e.nextElement()).update(worldTime);
        }
    }
    
    
    public void removeItem(int itemId) {
        
        item_table.remove(new Integer(itemId));
    }
}